package com.base.proxy;


import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * FileName: JdkProxyFactory
 *
 * @author innocent
 * @date 2018/10/26 14:39
 */
public class JdkProxyFactory implements InvocationHandler {

    /**
     * 目标对象
     */
    private Object target;

    public JdkProxyFactory(Object target) {
        this.target = target;
    }

    public Object getProxyInstance() {
        Class<?> clazz = target.getClass();

        Object proxyInstance = Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), this);
        System.out.println("----->     " + proxyInstance.getClass());
        return proxyInstance;
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("日志输出");
        return method.invoke(target,args);
    }
}
